package cn.ronghuanet.car.doc;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 文档对象中要有哪些字段,要看门户网站列表页面要展示哪些字段,以及有哪些筛选条件
 */
@Document(indexName = "ronghuanet_car",type = "carDoc")
@Data
public class CarDoc {

    @Id
    private Long id;

    @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    private String title;

    @Field(type = FieldType.Keyword)
    private String cover;

    @Field(type = FieldType.Double)
    private BigDecimal saleprice;

    @Field(type = FieldType.Double)
    private BigDecimal costprice;

    @Field(type = FieldType.Integer)
    private Integer isnew;

    @Field(type = FieldType.Date)
    @JsonFormat(pattern = "yyyy-MM",timezone = "GMT+8")
    private String reigstertime;

    @Field(type = FieldType.Double)
    private Double mileage;

    @Field(type = FieldType.Long)
    private Long shopId;

    //@Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    @MultiField(
            mainField = @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart"),
            otherFields = {
                    @InnerField(suffix = "keyword", type = FieldType.Keyword)
            }
    )
    private String shopName;

    @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    private String shopAddress;

    @Field(type = FieldType.Date)
    private Date onsaletime;

    @Field(type = FieldType.Integer)
    private Integer costeffective;

    @Field(type = FieldType.Integer)
    private Integer rushsale;

    @Field(type = FieldType.Integer)
    private Integer quasinewcar;

    @Field(type = FieldType.Integer)
    private Integer transitivecountry;

    @Field(type = FieldType.Long)
    private Long typeId;

    //@Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    // 给typeName做多字段映射,主字段的名字是typeName,类型是text,还有一个字段的名字是typeName.keyword,类型是keyword
    @MultiField(
            mainField = @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart"),
            otherFields = {
                    @InnerField(suffix = "keyword", type = FieldType.Keyword)
            }
    )
    private String typeName;

    @Field(type = FieldType.Text, analyzer = "ik_smart", searchAnalyzer = "ik_smart")
    private String carInfo;
}
